package edu.ynu.se.xiecheng.repository;

import edu.ynu.se.xiecheng.entity.SoilData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface SoilDataRepository extends JpaRepository<SoilData, Long> {
    /**
     * 查询设备的最新数据
     */
    List<SoilData> findByDeviceIdOrderByCollectTimeDesc(Long deviceId);

    /**
     * 查询设备在指定时间范围内的数据
     */
    List<SoilData> findByDeviceIdAndCollectTimeBetweenOrderByCollectTimeAsc(
            Long deviceId, LocalDateTime startTime, LocalDateTime endTime);
    /**
     * 根据设备ID查询最新的一条土壤数据
     * @param deviceId 设备ID
     * @return 最新的一条土壤数据
     */
    SoilData findFirstByDeviceIdOrderByCollectTimeDesc(Long deviceId);

    List<SoilData> findByDeviceIdAndCollectTimeBetweenOrderByCollectTimeDesc(Long deviceId, LocalDateTime startTime, LocalDateTime endTime);
} 